/*
 * @Author: your cyz
 * @Date: 2020-05-18 10:57:43
 * @LastEditTime: 2021-05-18 09:47:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \slave_front\src\App.js
 */
// import 'antd/dist/antd.min.css';
import 'assets/scss/pages/login.scss'
import 'assets/scss/components/bgStyle.scss';
import 'assets/scss/pages/common.scss'

import { BrowserRouter as Router, Route,Switch ,Redirect} from 'react-router-dom'
import React, { Component ,Suspense,lazy} from 'react';
import {createBrowserHistory} from 'history';
import axios from 'requset/request';
import API from "api/Api.js"

import PageLoading from 'pages/error/pageLoading'
const BasicLayout = lazy(()=>import('layouts/index.jsx'))
const BlackLayout = lazy(()=>import('layouts/blankLayout.jsx'))
// const MaintenanceLayout = lazy(()=>import('layouts/maintenanceLayout.jsx'))

export const history = createBrowserHistory();

class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            status:false,
        }
    }
    handleAuth=()=>{
        const userinfo = sessionStorage.getItem('userinfo');
        if(userinfo !=null){
            const user = JSON.parse(userinfo);
            this.setState({
                status:true
            })
        }
    }
    componentDidMount(){
        this.fnGetLogo();
    }
    componentWillMount(){
        // this.handleAuth();
    }
    fnGetLogo(){
        axios.get(API.qryserverInfo).then((res) =>{
          if(res.data.code ==0){
              var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
              link.type = 'image/x-icon';
              link.rel = 'shortcut icon';
              
              let ip = res.data.data.serverInfo.ip
              let port = res.data.data.serverInfo.port

              if(res.data.data.serverInfo.logo){
                window.document.title=res.data.data.serverInfo.name;

                let logo = res.data.data.serverInfo.logo 
                link.href = ip+":"+port+"/iots/mpPhotoSrc/"+logo;
              }else{
                window.document.title="迅微IOT监控管理系统"
                
                link.href = './logo.png';
              }
              document.getElementsByTagName('head')[0].appendChild(link);
              localStorage.setItem("serverUrl",JSON.stringify(res.data.data.serverInfo))
          }
        });
    }
    fnIsAuthPassPage(data){
        let flag = false;
        switch(data){
            case '/login':
            case '/page404':
            case '/pageNoMenu':
            case '/pageInit':
            case '/retrievePass':
            case '/pageNoPer':
            case '/drivingRoute':
            case '/threeScreen':
                flag = true;
                break;
        }
        return flag;
    }
    fnIsMaintenancePage(data){
        let flag = false;
        switch(data){
            case '/emHome':
                flag = true;
                break;
            case '/emnewWorksheet':
                flag = true;
                break;
            case '/emWorksheet':
                flag = true;
                break;
            case '/emWsDistribute':
                flag = true;
                break;
            case '/enWsHistory':
                flag = true;
                break;
            case '/emRole':
                flag = true;
                break;
            case '/emUser':
                flag = true;
                break;
            case '/emLog':
                flag = true;
                break;
            case '/blacklist':
                flag = true;
                break; 
            case '/evaluate':
                flag = true;
                break;
            case '/Orderdetails':
                flag = true;
                break; 
            case '/emSalesPolicy':
                flag = true;
                break;  
        }
        return flag;
    }
    authorUser=(data)=>{
        // let path = data.location.pathname;
        // if(this.fnIsAuthPassPage(path)){
        //     return <BlackLayout />
        // }
        // else if(this.fnIsMaintenancePage(path)){
        //     return <MaintenanceLayout />
        // }
        // else{
        //     return <BasicLayout />
        // }
        // if(this.state.status){
           
        // }else{
        //     return <BlackLayout />
        // }
        return <BlackLayout />
    }
    render() {
        return (
            <Router history={history} basename='/iots'>
                <Switch>
                    <Suspense fallback={<PageLoading />}>
                        <Route 
                            path="/"
                            render={props =>this.authorUser(props)}
                        />
                    </Suspense>
                </Switch>
            </Router>
        );
    }
}

export default App;